package com.example.message.service;

import com.example.message.handler.SysMessageHandler;
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

@Service
public class SysFileMessageListener extends FileAlterationListenerAdaptor {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private List<SysMessageHandler> handlers = new ArrayList<>();

    @Override
    public void onFileCreate(File file) {
        for (SysMessageHandler handler : handlers) {
            handler.receive(file.getName());
        }
    }
}
